import Vue from 'vue'
import Router from 'vue-router'

import Main from '../views/Main'
import Category from "../views/Category";
import Tag from "../views/Tag";
import Message from "../views/Message";
import Articles from "@/components/Article/Articles";
import Search from "@/views/Search";
import Article from "@/views/Article";
import timeLine from "@/views/timeLine";
Vue.use(Router);

const router = new Router({
    mode:"history",
    routes: [
        {
            path:'/',
            name:"Main",
            component:Main,
            meta:{
                title: "首页"
            }
        },
        {
            path:'/articles/:theme',
            name:"Articles",
            component:Articles,
            meta:{
                title: "文章"
            }
        },
        {
            path: '/main',
            name: 'Main',
            component: Main,
            meta:{
                title: "首页"
            }
        },
        {
            path:"/category/:name",
            name:"Category",
            component:Category,
            meta:{
                title:"分类"
            }
        },
        {
            path:"/tag/:name",
            name:"Tag",
            component:Tag,
            meta:{
                title:"标签"
            }
        },
        {
            path:"/message",
            name:"message",
            component:Message,
            meta:{
                title:"分类"
            }
        },
        {
            path:"/search",
            name:"Search",
            component:Search,
            meta:{
                title:"搜索"
            }
        },
        {
            path:"/article/:id",
            name:"Article",
            props:true,
            component:Article,
            meta:{
                title:"文章"
            }
        },
        {
            path:"/timeLine",
            name:"TimeLine",
            component:timeLine,
            meta:{
                title:"时间轴"
            }
        }
    ]
})
router.beforeEach((to,from,next)=>{

    if(to.meta.title)
        document.title=to.meta.title;
    next();
})
//登录检测
/*router.beforeEach((to,from,next)=>{
    if(to.path==='/login')
        next();
    else{
        let token=window.sessionStorage.getItem('token');
        if(token===null||token===''){
            next('/login');
        }else
            next();
    }
})*/

export default router;
